import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:background_fetch/background_fetch.dart';


class TestIsRun extends StatefulWidget {
  @override
  _TestIsRunState createState() => _TestIsRunState();
}

class _TestIsRunState extends State<TestIsRun> with WidgetsBindingObserver {

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    print("--" + state.toString());
    switch (state) {
      case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。
      print('这个是状态11111111');
        break;
      case AppLifecycleState.resumed:// 应用程序可见，前台
        print('这个是状态222222>>>>...前台');

        break;
      case AppLifecycleState.paused: // 应用程序不可见，后台
        print('这个是状态33333>>>>...后台');

        break;
//      case AppLifecycleState.suspending: // 申请将暂时暂停
//        break;
      case AppLifecycleState.detached:
        // TODO: Handle this case.
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(
            title: const Text('前后台测试')
        ),
        body: Container(
          color: Colors.black,
          child: Text('前后台测试'),
        ),
      );
  }



  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
}

